package com.zhouqinuan.spring.cloud.develop.framework.web.config.i18n;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

public class MyLocaleResolver implements LocaleResolver {

    private Locale defaultLocale = Locale.CHINA;

    private String paramName = "locale";

    @Override
    public Locale resolveLocale(HttpServletRequest request) {

        String locale = request.getParameter(paramName);

        if (StringUtils.isEmpty(locale)) {
            return defaultLocale;
        }

        return StringUtils.parseLocaleString(locale);
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
        
    }

    public Locale getDefaultLocale() {
        return defaultLocale;
    }

    public void setDefaultLocale(Locale defaultLocale) {
        this.defaultLocale = defaultLocale;
    }
}
